package com.itheima.company.service.impl;

import com.itheima.company.pojo.Company;
import com.itheima.company.service.CompanyService;
import com.itheima.company.mapper.CompanyMapper;
import com.itheima.common.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author IntelliJ IDEA
 * @date 2020/10/18  10:25
 */  //设置token的过期时间

@Service
@Transactional
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyMapper companyMapper;

    @Autowired
    private IdWorker idWorker;

    /**
     * 查询所有企业
     */
    @Override
    public List<Company> findCompanys() {
        return companyMapper.findCompanys();
    }

    /**
     * 根据id查询企业
     */
    @Override
    public Company findCompanyById(String id) {
        return companyMapper.findCompanyById(id);
    }

    /**
     * 根据id删除企业
     */
    @Override
    public Integer deleteCompanyById(String id) {
        return companyMapper.deleteCompanyById(id);

    }

    /**
     * 根据id修改企业
     */
    @Override
    public Integer updateCompanyById(Company company) {
        return companyMapper.updateCompanyById(company);
    }

    /**
     * 新增企业
     */
    @Override
    public Integer addCompany(Company company) {
        company.setId(idWorker.nextId()+"");
        company.setCreateTime(new Date());
        return  companyMapper.addCompany(company);
    }
}
